package controller;

import beans.RunningTaskBean;
import engine.BIEngine0_1.ParseTaskJson;
import engine.BIEngine0_1.TaskThread;

import java.io.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class TaskStateServlet
 */
public class TaskStateServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public TaskStateServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	@SuppressWarnings("Duplicates")
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException{
		StringBuilder jsonStringBuilder = new StringBuilder();
		try {
			BufferedReader br = new BufferedReader(new FileReader(new File("/home/beirut/Documents/lab_file/rubic/json/zykkkkk.json")));
//			BufferedReader br = new BufferedReader(new FileReader(new File("C:/Users/Administrator/Desktop/json/new_model_parse.json")));
			String temp = "";
			while ((temp = br.readLine()) != null) {
				jsonStringBuilder.append(temp);
			}
			br.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
//		TaskThread taskA = new TaskThread("task_a_id", "task_a_hash", jsonStringBuilder.toString(), "task_a_name");
//		taskA.start();
		ParseTaskJson parser = new ParseTaskJson();
		RunningTaskBean runningTaskBean = new RunningTaskBean("taskId","taskHash",jsonStringBuilder.toString(),"taskName");
		TaskThread task = new TaskThread(runningTaskBean);
//		runningTaskBean.setRunnableObjects(parser.toRunnerableObjectMap(task));
		task.start();
	}

}
